#ifndef PROPERTYMANAGER_H
#define PROPERTYMANAGER_H


#include <string>
#include <map>


#include <boost/any.hpp>

#include "../OgreFramework.h"

class PropertyManager
{
public:
    PropertyManager();
    virtual ~PropertyManager();

    template <class T> T getPropertyValue(std::string _name)
    {
        T r;

//        OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : "+_name );

        if (m_properties.count(_name)>0)
        {
        //    OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : "+_name+"   nombre sup a zero" );

            try
            {
         //       OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : "+_name+"   avant le cast" );
                r = boost::any_cast<T>(m_properties[_name]);
        //        OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : "+_name+"   apres le cast" );
            }
            catch(boost::bad_any_cast& bac) // nous attrapons l'exception
            {

                OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : "+_name +"   invalid type recquired");
            }

        }
        else
        {
            OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : no property named "+_name +"   ");
            //return 0;
        }


        return r;
    }


    template <class T> void setPropertyValue(std::string _name, T _value)
    {
        if (m_properties.count(_name)==1)
        {
            m_properties[_name] = boost::any(_value);
        }
        else
        {
            OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : no property named "+_name +"   ");
        }
    }

    template <class T> void addProperty(std::string _name, T _value)
    {
        if (m_properties.count(_name)==0)
        {
            m_properties.insert(std::pair<std::string, boost::any>(_name,boost::any(_value)));
        }
        else
        {

            OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : already a property named property named "+_name +"   ");
            setPropertyValue<T>(_name, _value);
        }


    }
    void removeProperty(std::string _name)
    {
        if (m_properties.count(_name)==1)
        {
            m_properties.erase(_name);
        }
        else
        {
            OgreFramework::getSingletonPtr()->m_pLog->logMessage("getPropertyValue : no property named "+_name +"   ");
        }
    }


protected:
private:



    std::map<std::string, boost::any > m_properties;

};




#endif // PROPERTYMANAGER_H
